package ru.urfc.portal.operations;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.ejb.Stateless;

import ru.urfc.portal.model.radio.DeviceCertificate;

@Stateless
public class DeviceCertificatesFilter {

	public List<DeviceCertificate> filter(List<DeviceCertificate> items) {
		List<DeviceCertificate> result = new ArrayList<DeviceCertificate>();
		List<DeviceCertificate> sortedItems = new ArrayList<DeviceCertificate>(items);
		Collections.sort(sortedItems);
		Collections.reverse(sortedItems);
		DeviceCertificate previous = null;
		for (DeviceCertificate item: sortedItems) {
			if (previous == null || item.compareGuids(previous) != 0) {
				result.add(item);
				previous = item;
			}				
		}
		Collections.reverse(result);
		return result;
	}

}
